//
//  GLCanvas.m
//  LMPhotoVideoSDK
//
//  Created by Aimar on 16/7/19.
//  Copyright © 2016年 魁钺会. All rights reserved.
//

#import "GLCanvas.h"

#define KSTACK_SIZE_MAX     20

@interface GLCanvas () {
    Matrix4<float>      _projection;
    Matrix4<float>      _stack[KSTACK_SIZE_MAX];
    
    int                 _top;
}

@end

@implementation GLCanvas

- (void)setProjection:(Matrix4<float>)projection {
    _projection = projection;
}

- (Matrix4<float>)getProjection {
    return _projection;
}

- (void)save {
    NSAssert(_top < KSTACK_SIZE_MAX - 1, @"矩阵栈上限溢出");
    Matrix4<float> mat = _stack[_top++];
    _stack[_top] = mat;
}

- (Matrix4<float>)currentMatrix {
    return _stack[_top];
}

- (void)setCurrentMatrix:(Matrix4<float>)matrix {
    _stack[_top] = matrix;
}

- (void)restore {
    NSAssert(_top > 0, @"矩阵栈下限溢出");
    _top--;
}

@end
